package com.nacos.shangtu.service.impl;

import com.nacos.shangtu.entity.po.UserPO;
import com.nacos.shangtu.mapper.GroupUserMapper;
import com.nacos.shangtu.mapper.UserMapper;
import com.nacos.shangtu.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Slf4j
@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private GroupUserMapper groupUserMapper;

    @Autowired
    private UserMapper userMapper;

    @Override
    public void syncUser(UserPO userPO) {
        UserPO user = userMapper.selectByUserId(userPO.getUserId());
        if (user != null) {
            user.setUserName(userPO.getUserName());
            user.setAvatarUrl(userPO.getAvatarUrl());
            userMapper.updateById(user);
            log.info("update user - {}.", userPO.getUserId());
        } else {
            userMapper.insert(userPO);
            log.info("insert user - {}.", userPO.getUserId());
        }
    }
}
